package exercise.jslide.jslide.view.dialog;

import exercise.jslide.jslide.utils.SerializableColor;
import javafx.geometry.Insets;
import javafx.scene.control.ColorPicker;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.geometry.Pos;

public class ColorPickerDialog {
    private Stage stage;
    private ColorPicker colorPicker;
    private SerializableColor selectedColor;

    // 构造函数
    public ColorPickerDialog(Stage parentStage) {
        stage = new Stage();
        stage.initOwner(parentStage); // 设置父窗口
        stage.initModality(Modality.WINDOW_MODAL); // 设置为模态对话框
        stage.setTitle("选择颜色");
        stage.getIcons().add(new Image(getClass().getResourceAsStream("/exercise/jslide/jslide/app/icons/LOGO.png")));
        colorPicker = new ColorPicker();
        Button okButton = new Button("确定");
        okButton.setOnAction(e -> {
            selectedColor = new SerializableColor(colorPicker.getValue());
            stage.close();
        });

        VBox layout = new VBox(20); // 设置垂直间距为20
        layout.setPadding(new Insets(20)); // 设置内边距为20
        layout.setAlignment(Pos.CENTER); // 设置对齐方式为居中
        layout.getChildren().addAll(colorPicker, okButton);

        Scene scene = new Scene(layout, 250, 200); // 调整窗口大小
        stage.setScene(scene);
    }

    // 显示对话框
    public void show() {
        stage.showAndWait();
    }

    // 隐藏对话框
    public void hide() {
        stage.close();
    }

    // 获取选择的颜色
    public SerializableColor getColor() {
        return selectedColor;
    }
}